$(function () {
    if (editType != 'info') {
        regValidate(["#_tabDataForm"]);
    }
});

function doTabSave() {
    if(!$("#_tabDataForm").valid()) return;//校验不通过
    var tabName = $.trim($('#tabName').val());
    var tabCode = $.trim($('#tabCode').val());
    var tabUrl = $.trim($('#tabUrl').val());
    var menuId = $('#menuId').val();
    var sortNum = $.trim($('#sortNum').val());
    if (!sortNum || sortNum == '') {
        sortNum = 999;
    }
    var postData = {
        tabName : tabName,
        tabCode : tabCode,
        tabUrl : tabUrl,
        menuId : menuId,
        sortNum : sortNum
    };
    var url = basePath + 'tab/addTab?t=' + new Date().getTime();
    if (editType == 'edit') {
        postData.id = oneTabInfo.id;
        url = basePath + 'tab/editTab?t=' + new Date().getTime();
    }
    $.ajax({
        type: 'post',
        url: url,
        dataType: 'json',
        data: postData,
        success : function (data) {
            if (!data) {
                toastr.error(common_save_fail);
                return;
            }
            if (data.isSuccess) {
                toastr.success(common_save_success);
                doBack();
                return;
            }
            if (!data.isSuccess && data.errorCode == 'EXIST_CODE') {
                toastr.error('【'+tabName+'】编码已存在');
                return;
            }
            if (!data.isSuccess) {
                toastr.error(data.errorDesc);
                return;
            }
        },
        error: function (request) {
            toastr.error(common_system_error);
            return;
        }
    });
}

function doBack() {
    var menuIdStr = (searchInfo.menuId && searchInfo.menuId != '') ? ('&menuId=' + searchInfo.menuId) : '';
    window.location.href = basePath + 'tab/tabPage?status=' + searchInfo.status + menuIdStr +
        '&t=' + new Date().getTime() + '&pageNo=' + searchInfo.pageNo + '&pageSize=' + searchInfo.pageSize;
}

function doCheckDataChange() {
    var data = getFromData('#_tabDataForm');
    var checkData = {
        tabName : $.trim(data.tabName),
        tabCode : $.trim(data.tabCode),
        tabUrl : $.trim(data.tabUrl),
        menuId : data.menuId,
        sortNum : $.trim(data.sortNum)
    };
    if (editType != 'info' && (!Compare(checkData, oneTabInfo))) {
        swalClosePageToastr(doBack);
        return;
    }
    doBack();
}